import { app, BrowserWindow, dialog } from 'electron';
import _ from 'lodash';
import ThreadController from './scancontrol';

export function OpenDirectory() {
    dialog.showOpenDialog({ properties: ['openDirectory'] }, dirs => {
        if (_.isUndefined(dirs) && _.isEmpty(dirs)) {
            BrowserWindow.getAllWindows()[0].webContents.send('directory-selected', null);
            return;
        }
        BrowserWindow.getAllWindows()[0].webContents.send('directory-selected', dirs[0]);
        ThreadController.restartThread();
        ThreadController.scanPath(dirs[0]);
    });
}
